<?php 
## include required files
/*******************************/
require_once '../model/users.php';
require_once '../model/moduleuser.php';
## Paginaton class
require_once ("../includes/classes/pagination_class.php");
/*******************************/

## Create Objects
/*******************************/
$userObj = new Model_Users();
$moduleObj=new Model_ModuleUser();
/*******************************/

/*******************************/
## Active, Inactive selected records
/*******************************/
if(isset($_POST['go']) != '' && isset($_POST['action']) != '') {
		$ids = implode(",", $_POST['checkall']);
		## check which action is selected
		if(trim($ids) != '' ) {
			$hidden_page = $_POST['hidden_pageno'];	
			if($_POST['action'] == 'delete') {
				## Delete selected records
				$userObj->deleteMultiplereportabuse($ids);
				$_SESSION['msg']="<div class='success_msg'><span>Report Abuse(s) deleted successfully</span></div>";
			}
				header('location:'.SITE_URL.'/admin/home.php?q=reportabuse&page='.$hidden_page);
				exit;
		}
		
} // if close



if(isset($_GET['action']) == 'delete' && isset($_GET['id']) != '') {
	$id = base64_decode($_GET['id']);
	## Delete Country category
	$userObj->deleteReportAbuseById($id);
	$_SESSION['msg']="<div class='success_msg'><span>Report Abuse deleted successfully.</span></div>";
	header('location:'.SITE_URL.'/admin/home.php?q=reportabuse&page='.$_GET['page']);
	exit;
}



if($_GET['q']=='reportabuse')
{
	$moduelArray=$moduleObj->getModuleHelpText(23);
	$smarty->assign('moduelArray', $moduelArray);
	//echo '<pre>';print_r($moduelArray);exit;
}
##Fetch all cms pages from database
## Get search parameters in variables - 
if($_POST['search'] != '' && $_POST['search'] != 'Tradesman Name and Comment') {
	$searchindex = addslashes($_POST['search']);
} else if($_GET['search'] != '') {
	$searchindex = addslashes($_GET['search']);
} else {
	$searchindex = '';
}
$searchindex=trim($searchindex);
$smarty->assign('search',stripslashes (stripslashes ($searchindex)));

if($_GET['col1'] != '') {
	$col1 = base64_decode($_GET['col1']);
}
else if($_GET['col2'] != '') 
{
	$col2 = base64_decode($_GET['col2']);
} 
else
{
	$col1 = 0;
}

##  --------- Pagination part first start --------------##
	if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != "" ) {
		$pageNum = $_GET[ 'page' ];
	} else {
		$pageNum = 1;
	} 
	$rowsPerPage = ROW_PER_PAGE;
	if($_GET['col1'] != '') {
		$pageName = "home.php?q=reportabuse&col1=".$_GET['col1'].""; 
	} 
	else if($_GET['col2'] != '') 
	{
		$pageName = "home.php?q=reportabuse&col2=".$_GET['col2'].""; ;
	} 
	else {
		$pageName = "home.php?q=reportabuse"; 	
	}
	## Count all the records
	$reportArray = $userObj->getAllReportAbuse($searchindex,$col1,$col2);
	$total_rows = count($reportArray);
	$offset	= ($pageNum - 1) * $rowsPerPage;
	$smarty->assign('page', $pageNum);
##  --------- Pagination part first end --------------##


##  --------- Pagination part second start --------------##
	$newid = $pageNum * $rowsPerPage - $rowsPerPage + 1;
	$smarty->assign('newid', $newid);
	$reportArray = $userObj->getAllReportAbuse($searchindex,$col1,$col2,$rowsPerPage,$offset);
	//echo "<pre>"; print_r($reportArray);exit;
	$smarty->assign('reportArray', $reportArray);
	if($total_rows > ROW_PER_PAGE) {
		$pg = new pagination();					// CREATING OBJECT OF THE PAGINATION CLASS
		$pgnation = $pg->pagination_admin( $total_rows , $rowsPerPage , $pageNum , $pageName , $other_id, $class);	
		$smarty-> assign("pagination",$pgnation);
	}
##  --------- Pagination part second end --------------##	

## Assign session message to smarty variable and unset session variable
if($_SESSION['msg'] != '') {
	$smarty->assign('msg', $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

## Set active class variable for left menu (main menu and sub menu)
$smarty->assign('activeclass', 'reportabuse');
$smarty->assign('mainmenu', '3');

## Unset all the objects created which are on this page
unset($userObj);
unset($moduleObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'reportabuse/reportabuse.tpl');
unset($smarty);
?>